﻿using Core.Models;
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;

namespace Core.FrameWork
{
    public class DataDBContext:DbContext
    {
        public DataDBContext() { }
        public DataDBContext(DbContextOptions<DataDBContext> options):base(options)
        {

        }

        public DbSet<Person> Person { get; set; }

        /// <summary>
        /// 在模型创建时
        /// </summary>
        /// <param name="builder"></param>
        protected override void OnModelCreating(ModelBuilder builder)
        {
            base.OnModelCreating(builder);

            #region << 模型映射 >>

            builder.Entity<Person>(b =>
            {
                b.ToTable("Person","dbo");

                b.Property(t => t.Id)
                .HasColumnName("Id");
                
                b.Property(t => t.Name)
                .HasColumnName("Name")
                .HasMaxLength(50)
                .IsRequired();

                b.Property(t => t.Age)
               .HasColumnName("Age")
               .IsRequired();
            });
            #endregion
        }

    }
}
